package display.screens {
	
	import display.screens.apartments.ApartmentsScreenContent;
	import display.scrollableWindow.ScrollableWindow;
	
	import events.LoadingEvent;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.ilovecode.display.Gallery;
	import org.ilovecode.mvc.View;
	import org.ilovecode.screen.Screen;
	import org.ilovecode.screen.ScreenName;
	
	/**
	 * ...
	 * @author Vjekoslav Ratkajec
	 */
	public class ApartmentsScreen extends Screen {
		
		//{ region Stage elements
		
		//Content which will be loaded in scrollable window
		private var content:ApartmentsScreenContent;
		//Window to display content
		public var contentWindow:ScrollableWindow;
		//Interieurs gallery
		private var gallery:Gallery;
		
		//} endregion
		
		//{ region Constructor and intialization
		
		/**
		 * Create new instance of Apartments screen.
		 */
		public function ApartmentsScreen() {
			//init();
			super(ScreenName.APARTMENTS, "apartmentsScreen");
		}
		
		/**
		 * Initialize screen.
		 * 
		 * @private
		 */
		/*private function init():void {
			initListeners();
			
			//Setup content in window
			contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
		}*/
		
		/**
		 * Initialize listeners for components on screen.
		 * 
		 * @private
		 */
		/*private function initListeners():void {
			
		}*/
		
		//} endregion
		
		override protected function construct():void
		{
			super.construct();
			
			gallery = new Gallery(900, 530);
			content = new ApartmentsScreenContent();
		}
		
		override protected function initUI():void
		{
			super.initUI();
			
			contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
			
			var xml:XML = controller.getScreenXML("apartments");
			gallery.path = String(xml.gallery.@url);
			//gallery.path = "images/about/items.xml";
			gallery.thumbnailsContainerWidth = 124;
			gallery.thumbnailsContainerHeight = 281;
			this.addChild(gallery);
		}
		
		override protected function addListeners():void
		{
			super.addListeners();
			gallery.addEventListener(LoadingEvent.SHOW_PROGRESS_ICON, update);
			gallery.addEventListener(LoadingEvent.HIDE_PROGRESS_ICON, update);
		}
		
		override protected function removeListeners():void
		{
			super.removeListeners();
			gallery.removeEventListener(LoadingEvent.SHOW_PROGRESS_ICON, update);
			gallery.removeEventListener(LoadingEvent.HIDE_PROGRESS_ICON, update);
		}
		
		override protected function update(event:Event):void
		{
			switch(event.type)
			{
				case LoadingEvent.SHOW_PROGRESS_ICON:
					//Fallthrough
				case LoadingEvent.HIDE_PROGRESS_ICON:
					this.dispatchEvent(event.clone());
					break;
				default:
					super.update(event);
					break;
			}
		}
		
	}

}